﻿using System.Collections.Generic;
using PnJ.Aliyun.OTS.Models;
namespace PnJ.Aliyun.OTS
{
    public partial class OTSClient
    {

        #region Row操作
        /// <summary>
        /// 插入数据到指定的行，如果该行不存在，则新增一行；若该行存在，则覆盖原有行。
        /// </summary>
        /// <param name="putRowRequest"></param>
        /// <returns></returns>
        public PutRowResponse PutRow(PutRowRequest putRowRequest)
        {
            var putRowResponse = POST<PutRowRequest, PutRowResponse>("PutRow", putRowRequest);
            return putRowResponse;
        }
        /// <summary>
        /// 根据给定的主键读取单行数据.
        /// </summary>
        /// <param name="getRowRequest"></param>
        /// <returns></returns>
        public GetRowResponse GetRow(GetRowRequest getRowRequest)
        {
            var getRowResponse = POST<GetRowRequest, GetRowResponse>("GetRow", getRowRequest);
            return getRowResponse;
        }
        /// <summary>
        /// 更新指定行的数据，如果该行不存在，则新增一行；若该行存在，则根据请求的内容在这一行中新增、修改或者删除指定列的值。
        /// </summary>
        /// <param name="updateRowRequest"></param>
        /// <returns></returns>
        public UpdateRowResponse UpdateRow(UpdateRowRequest updateRowRequest)
        {
            var updateRowResponse = POST<UpdateRowRequest, UpdateRowResponse>("UpdateRow", updateRowRequest);
            return updateRowResponse;
        }
        /// <summary>
        /// 删除一行数据
        /// </summary>
        /// <param name="deleteRowRequest"></param>
        /// <returns></returns>
        public DeleteRowResponse DeleteRow(DeleteRowRequest deleteRowRequest)
        {
            var deleteRowResponse = POST<DeleteRowRequest, DeleteRowResponse>("DeleteRow", deleteRowRequest);
            return deleteRowResponse;
        }
        /// <summary>
        /// 读取指定主键范围内的数据。
        /// </summary>
        /// <param name="getRangeRequest"></param>
        /// <returns></returns>
        public GetRangeResponse GetRange(GetRangeRequest getRangeRequest)
        {
            var getRangeResponse = POST<GetRangeRequest, GetRangeResponse>("GetRange", getRangeRequest);
            return getRangeResponse;
        }
        /// <summary>
        /// 批量读取一个或多个表中的若干行数据。
        /// </summary>
        /// <param name="batchGetRowRequest"></param>
        /// <returns></returns>
        public BatchGetRowResponse BatchGetRow(BatchGetRowRequest batchGetRowRequest)
        {
            var batchGetRowResponse = POST<BatchGetRowRequest, BatchGetRowResponse>("BatchGetRow", batchGetRowRequest);
            return batchGetRowResponse;
        }

        /// <summary>
        /// 批量插入，修改或删除一个或多个表中的若干行数据。
        /// </summary>
        /// <param name="batchGetRowRequest"></param>
        /// <returns></returns>
        public BatchWriteRowResponse BatchWriteRow(BatchWriteRowRequest batchWriteRowRequest)
        {
            var batchWriteRowResponse = POST<BatchWriteRowRequest, BatchWriteRowResponse>("BatchWriteRow", batchWriteRowRequest);
            return batchWriteRowResponse;
        }
        #endregion

        #region Table操作
        /// <summary>
        /// 根据给定的表结构信息创建相应的表
        /// </summary>
        /// <param name="ctRequest"></param>
        /// <returns></returns>
        public bool CreateTable(CreateTableRequest ctRequest)
        {
            var ctResponseResult = POST<CreateTableRequest>("CreateTable", ctRequest);
            return ctResponseResult;
        }
        /// <summary>
        /// 获取当前实例下已创建的所有表的表名
        /// </summary>
        /// <returns></returns>
        public List<string> ListTable()
        {
            var ltReqeust = new ListTableRequest();
            var ltResponse = POST<ListTableRequest, ListTableResponse>("ListTable", ltReqeust);
            return ltResponse.TableNames;
        }
        /// <summary>
        /// 删除表
        /// </summary>
        /// <param name="tableName">表名</param>
        public bool DeleteTable(string tableName)
        {
            var dtRequest = new DeleteTableRequest(tableName);
            var dtResponseResult = POST<DeleteTableRequest>("DeleteTable", dtRequest);
            return dtResponseResult;
        }

        /// <summary>
        /// 修改表
        /// </summary>
        /// <param name="utRequest"></param>
        /// <returns></returns>

        public bool UpdateTable(UpdateTableRequest utRequest)
        {
            var utResponseResult = POST<UpdateTableRequest>("UpdateTable", utRequest);
            return utResponseResult;
        }
        /// <summary>
        /// 获取表信息
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <returns></returns>
        public DescribeTableResponse DescribeTable(string tableName)
        {
            var desRequest = new DescribeTableRequest(tableName);
            var desResponse = POST<DescribeTableRequest, DescribeTableResponse>("DescribeTable", desRequest);
            return desResponse;
        }

        #endregion
    }
}
